package com.itheima.wemedia.controller;

import com.itheima.common.vo.ResultVo;
import com.itheima.wemedia.pojo.WmMaterial;
import com.itheima.wemedia.pojo.WmUser;
import com.itheima.wemedia.service.WmMaterialService;
import com.itheima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ApiController {

    @Autowired
    private WmUserService wmUserService;

    @Autowired
    private WmMaterialService wmMaterialService;
    /**
     * 通过ap_user.id查询自媒体用户信息
     * @param apUserId
     * @return
     */
    @GetMapping("/api/wmUser/getByApUserId/{apUserId}")
    public ResultVo<WmUser> getByApUserId(@PathVariable(value = "apUserId") Long apUserId){
        WmUser wmUser=wmUserService.findByApUserId(apUserId);
        return ResultVo.ok(wmUser);
    }

    /**
     * 远程调用 添加自媒体账号
     * @param wmUser
     * @return
     */
    @PostMapping("/api/wmUser/add")
    public ResultVo<WmUser> add(@RequestBody WmUser wmUser){
       wmUserService.save(wmUser);
        return ResultVo.ok(wmUser);
    }

    /**
     * 远程调用 添加素材记录
     * @param wmMaterial
     * @return
     */
    @PostMapping("/api/wmMaterial/add")
    public ResultVo addWmMaterial(@RequestBody WmMaterial wmMaterial){
    wmMaterialService.save(wmMaterial);
    return ResultVo.ok();
    }
}
